package cn.kgc.boot.vue.controller;

import cn.kgc.boot.vue.entity.Student;
import cn.kgc.boot.vue.response.ResponseResult;
import cn.kgc.boot.vue.service.StudentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 课工场
 * @date 2025/9/12
 * @description
 */
@RestController
@RequestMapping("student")
@CrossOrigin
public class StudentController {
    @Resource
    private StudentService studentService;

    // 分页
    @RequestMapping("page")
    public ResponseResult studentPage(Integer page, Integer size) {

        Page<Student> studentPage = new Page<>(page, size);
        studentService.page(studentPage);

        // 封装分页数据
        List<Student> records = studentPage.getRecords();
        long total = studentPage.getTotal();

        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(records);
        responseResult.setCode(200);
        responseResult.setCount(total);

        return responseResult;
    }


}
